package com.socket.socketAsk;

import java.io.IOException;
import java.net.*;

/**
 * PetClient--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-09-14 16:21
 **/
public class PetClient {

    public static void main(String[] args) throws IOException {

        String mess = "您好，我想咨询一个问题";
        byte[] buff = mess.getBytes();
        InetAddress ia = InetAddress.getByName("localhost");
        DatagramPacket dp = new DatagramPacket(buff, buff.length, ia, 8081);
        DatagramSocket ds = new DatagramSocket();
        ds.send(dp);

        //================================
        byte[] buff2 = new byte[1024];
        DatagramPacket dp2 = new DatagramPacket(buff2, buff2.length);
        ds.receive(dp2);
        String repay = new String(buff2, 0,dp2.getLength());
        System.out.println("宠物店响应为：" + repay);
    }
}
